/*    */ package com.zimbra.cs.mime;
/*    */ 
/*    */ import java.io.IOException;
/*    */ import javax.mail.MessagingException;
/*    */ import javax.mail.internet.MimeBodyPart;
/*    */ import javax.mail.internet.MimeMessage;
/*    */ import javax.mail.internet.MimeMultipart;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class MimeFormatter
/*    */   extends MimeVisitor
/*    */ {
/* 36 */   private int mIndentLevel = 0;
/* 37 */   private StringBuilder mBuf = new StringBuilder();
/*    */   
/*    */   public boolean visitMessage(MimeMessage mm, MimeVisitor.VisitPhase visitPhase) throws MessagingException
/*    */   {
/* 41 */     if (visitPhase == MimeVisitor.VisitPhase.VISIT_BEGIN) {
/* 42 */       indent();
/* 43 */       this.mBuf.append("Message: " + Mime.getSubject(mm) + "\n");
/* 44 */       this.mIndentLevel += 1;
/*    */     } else {
/* 46 */       this.mIndentLevel -= 1;
/*    */     }
/* 48 */     return false;
/*    */   }
/*    */   
/*    */   public boolean visitMultipart(MimeMultipart mp, MimeVisitor.VisitPhase visitPhase) {
/* 52 */     if (visitPhase == MimeVisitor.VisitPhase.VISIT_BEGIN) {
/* 53 */       indent();
/* 54 */       this.mBuf.append("Multipart:\n");
/* 55 */       this.mIndentLevel += 1;
/*    */     } else {
/* 57 */       this.mIndentLevel -= 1;
/*    */     }
/* 59 */     return false;
/*    */   }
/*    */   
/*    */   public boolean visitBodyPart(MimeBodyPart bp) throws MessagingException {
/* 63 */     indent();
/* 64 */     this.mBuf.append("Part: type=" + bp.getContentType() + ", filename=" + bp.getFileName() + "\n");
/* 65 */     if (bp.getContentType().startsWith("text")) {
/* 66 */       this.mBuf.append("----------\n");
/*    */       try {
/* 68 */         this.mBuf.append(bp.getContent());
/*    */       } catch (IOException e) {
/* 70 */         this.mBuf.append(e + "\n");
/*    */       }
/* 72 */       this.mBuf.append("----------\n");
/*    */     }
/* 74 */     return false;
/*    */   }
/*    */   
/*    */   private void indent() {
/* 78 */     for (int i = 0; i < this.mIndentLevel; i++) {
/* 79 */       this.mBuf.append("  ");
/*    */     }
/*    */   }
/*    */   
/*    */   public String toString() {
/* 84 */     return this.mBuf.toString();
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mime/MimeFormatter.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */